// API和服务相关类型定义

import { Color, ColorScheme, User, UserPreferences, ColorUsageStats } from './index';

// API响应基础类型
export interface ApiResponse<T = any> {
  success: boolean;
  data?: T;
  message?: string;
  error?: string;
  timestamp: string;
}

// 分页参数
export interface PaginationParams {
  page: number;
  limit: number;
  sortBy?: string;
  sortOrder?: 'asc' | 'desc';
}

// 分页响应
export interface PaginatedResponse<T> {
  items: T[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;
}

// 色彩推荐请求参数
export interface ColorRecommendationRequest {
  baseColor: Color;
  schemeType: 'complementary' | 'analogous' | 'triadic' | 'tetradic';
  count?: number;
  preferences?: {
    brightness?: 'light' | 'dark' | 'mixed';
    saturation?: 'low' | 'medium' | 'high' | 'mixed';
  };
}

// 色彩分析请求参数
export interface ColorAnalysisRequest {
  colors: Color[];
  analysisType: 'harmony' | 'contrast' | 'accessibility' | 'mood';
}

// 色彩分析响应
export interface ColorAnalysisResponse {
  score: number; // 0-100
  recommendations: string[];
  issues?: string[];
  details: {
    harmony?: number;
    contrast?: number;
    accessibility?: {
      wcagAA: boolean;
      wcagAAA: boolean;
      contrastRatio: number;
    };
    mood?: {
      warmth: number; // -100 to 100
      energy: number; // 0-100
      sophistication: number; // 0-100
    };
  };
}

// 导入导出服务类型
export interface ImportRequest {
  data: string;
  format: 'json' | 'css' | 'sass' | 'adobe-ase' | 'sketch-palette';
}

export interface ExportRequest {
  schemes: ColorScheme[];
  format: 'json' | 'css' | 'sass' | 'adobe-ase' | 'sketch-palette';
  options?: {
    includeMetadata?: boolean;
    variableNames?: boolean;
    cssPrefix?: string;
  };
}

// 存储服务接口
export interface StorageService {
  // 用户数据
  getUser(): Promise<User | null>;
  saveUser(user: User): Promise<void>;
  
  // 偏好设置
  getPreferences(): Promise<UserPreferences>;
  savePreferences(preferences: UserPreferences): Promise<void>;
  
  // 色彩方案
  getColorSchemes(): Promise<ColorScheme[]>;
  saveColorScheme(scheme: ColorScheme): Promise<void>;
  deleteColorScheme(id: string): Promise<void>;
  
  // 统计数据
  getStats(): Promise<ColorUsageStats>;
  updateStats(stats: ColorUsageStats): Promise<void>;
  
  // 导入导出
  exportData(): Promise<string>;
  importData(data: string): Promise<void>;
  
  // 清理
  clearAll(): Promise<void>;
}

// 推荐引擎接口
export interface RecommendationEngine {
  generateComplementaryColors(baseColor: Color): Promise<Color[]>;
  generateAnalogousColors(baseColor: Color): Promise<Color[]>;
  generateTriadicColors(baseColor: Color): Promise<Color[]>;
  generateTetradicColors(baseColor: Color): Promise<Color[]>;
  generatePersonalizedRecommendations(baseColor: Color, userHistory: ColorScheme[]): Promise<Color[]>;
  generateTrendingRecommendations(baseColor: Color): Promise<Color[]>;
}

// 分析服务接口
export interface AnalyticsService {
  getUserStats(userId: string): Promise<ColorUsageStats>;
  analyzeColorHarmony(colors: Color[]): Promise<number>;
  analyzeColorContrast(color1: Color, color2: Color): Promise<number>;
  generateInsights(stats: ColorUsageStats): Promise<string[]>;
  detectColorTrends(): Promise<Color[]>;
}

// 错误处理类型
export interface AppError {
  code: string;
  message: string;
  details?: any;
  timestamp: Date;
  stack?: string;
}

// 日志级别
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';

// 日志条目
export interface LogEntry {
  level: LogLevel;
  message: string;
  data?: any;
  timestamp: Date;
  source?: string;
}